<template>
  <div style="width: 100%;display: block;">
    <el-row class="scroll-style">
      <el-form ref="scrollForm" :model="scrollForm" label-width="80px" size="mini">
        <el-form-item :label="$t('chart.scroll')" class="form-item">
          <el-checkbox v-model="scrollForm.open" @change="changeScrollCfg">{{ $t('chart.open') }}</el-checkbox>
          <el-tooltip class="item" effect="dark" placement="bottom">
            <div slot="content">
              明细表仅在分页模式为"下拉"时生效。
            </div>
            <i class="el-icon-info" style="cursor: pointer;color: gray;font-size: 12px;" />
          </el-tooltip>
        </el-form-item>
        <span v-show="scrollForm.open">
          <el-form-item :label="$t('chart.row')" class="form-item">
            <el-input-number v-model="scrollForm.row" :min="1" :max="1000" :precision="0" size="mini" @change="changeScrollCfg" />
          </el-form-item>
          <el-form-item :label="$t('chart.interval') + '(ms)'" class="form-item">
            <el-input-number v-model="scrollForm.interval" :min="500" :step="1000" :precision="0" size="mini" @change="changeScrollCfg" />
          </el-form-item>
        </span>
      </el-form>
    </el-row>
  </div>
</template>

<script>
import { DEFAULT_SCROLL } from '@/views/chart/chart/chart'

export default {
  name: 'ScrollCfg',
  props: {
    chart: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      scrollForm: JSON.parse(JSON.stringify(DEFAULT_SCROLL))
    }
  },
  watch: {
    'chart': {
      handler: function() {
        this.initData()
      }
    }
  },
  mounted() {
    this.initData()
  },
  methods: {
    initData() {
      const chart = JSON.parse(JSON.stringify(this.chart))
      if (chart.senior) {
        let senior = null
        if (Object.prototype.toString.call(chart.senior) === '[object Object]') {
          senior = JSON.parse(JSON.stringify(chart.senior))
        } else {
          senior = JSON.parse(chart.senior)
        }
        if (senior.scrollCfg) {
          this.scrollForm = senior.scrollCfg
        } else {
          this.scrollForm = JSON.parse(JSON.stringify(DEFAULT_SCROLL))
        }
      }
    },
    changeScrollCfg() {
      this.$emit('onScrollCfgChange', this.scrollForm)
    }
  }
}
</script>

<style scoped>
.shape-item{
  padding: 6px;
  border: none;
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.form-item-slider ::v-deep .el-form-item__label{
  font-size: 12px;
  line-height: 38px;
}
.form-item ::v-deep .el-form-item__label{
  font-size: 12px;
}
.el-select-dropdown__item{
  padding: 0 20px;
}
span{
  font-size: 12px
}
.el-form-item{
  margin-bottom: 6px;
}

.switch-style{
  position: absolute;
  right: 10px;
  margin-top: -4px;
}
.color-picker-style{
  cursor: pointer;
  z-index: 1003;
}

.scroll-style ::v-deep .el-input-number--mini {
  width: 120px !important;
}
</style>
